<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>部门管理</title> <!-- 修改标题 -->
    <!-- 引入外部资源（与user.html一致） -->
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/style.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/toastify-js/1.12.0/toastify.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/gridjs/6.2.0/theme/mermaid.min.css" rel="stylesheet" />
    <script src="https://cdn.bootcdn.net/ajax/libs/toastify-js/1.12.0/toastify.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/gridjs/6.2.0/gridjs.umd.js"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <!-- 侧边栏：高亮部门管理 -->
        <nav class="col-md-3 col-lg-2 d-md-block bg-light sidebar">
            <div class="position-sticky">
                <div class="sidebar-brand d-flex align-items-center px-3 py-3 border-bottom">
                    <i class="fas fa-building fa-2x me-2 text-primary"></i>
                    <span class="fs-5 fw-bold">部门管理系统</span>
                </div>
                <ul class="nav flex-column pt-3">
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="user.html" id="userManagementLink"> <!-- 取消active -->
                            <i class="fas fa-users fa-fw me-2"></i>
                            用户管理
                        </a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link active" href="department.html" id="departmentManagementLink"> <!-- 添加active -->
                            <i class="fas fa-building fa-fw me-2"></i>
                            部门管理
                        </a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="role.html" id="roleManagementLink">
                            <i class="fas fa-user-tag fa-fw me-2"></i>
                            角色管理
                        </a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="profile.html" id="profileLink">
                            <i class="fas fa-user-circle fa-fw me-2"></i>
                            个人信息
                        </a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="#" id="logoutLink" onclick="logout()">
                            <i class="fas fa-sign-out-alt fa-fw me-2"></i>
                            退出登录
                        </a>
                    </li>
                </ul>
            </div>
        </nav>

        <!-- 主内容区域：修改标题 -->
        <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
            <div class="row mb-4">
                <div class="col-12 d-flex justify-content-between align-items-center">
                    <div>
                        <h2 class="mb-0">
                            <i class="fas fa-building text-primary me-2"></i>
                            部门管理 <!-- 修改标题 -->
                        </h2>
                    </div>
                    <div>
                        <button data-bs-toggle="modal" data-bs-target="#deptModal" class="btn btn-success" onclick="openAddModal()">
                            <i class="fas fa-plus-circle me-1"></i> 新增部门 <!-- 修改按钮文字 -->
                        </button>
                        <button class="btn btn-outline-secondary ms-2" id="btnRefresh" onclick="initGrid()">
                            <i class="fas fa-sync-alt me-1"></i> 刷新
                        </button>
                    </div>
                </div>
            </div>

            <!-- 搜索表单（简化，保留基础结构） -->
            <div class="row">
                <div class="col-12">
                    <div class="card-header bg-white d-flex justify-content-between align-items-center border-bottom">
                        <form id="search-form" class="row row-cols-lg-auto g-3 align-items-center">
                            <div class="col-12">
                                <div class="input-group">
                                    <input type="text" class="form-control" name="name" placeholder="部门名称">
                                </div>
                            </div>
                            <div class="col-12">
                                <select class="form-select" name="enableState">
                                    <option disabled selected value="">状态</option>
                                    <option value="启用">启用</option>
                                    <option value="停用">停用</option>
                                </select>
                            </div>
                            <div class="col-12">
                                <button type="submit" class="btn btn-primary"><i class="fas fa-search"></i> 查询</button>
                                <button type="reset" class="btn btn-secondary"><i class="fas fa-redo"></i> 重置</button>
                            </div>
                        </form>
                    </div>
                    <div class="card-body p-0">
                        <div class="table-responsive">
                            <div id="gridjs-container" style="min-height: 400px;"></div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 部门模态框（合并新增/编辑，简化字段） -->
            <div class="modal fade modal-lg" id="deptModal" tabindex="-1" aria-labelledby="deptModalLabel" aria-hidden="true">
                <form id="dept-form" class="needs-validation" novalidate>
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h5 class="modal-title" id="deptModalLabel">新增部门</h5> <!-- 动态切换标题 -->
                                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                            </div>
                            <div class="modal-body">
                                <div class="px-5">
                                    <div id="alertMessage" class="mb-3"></div>
                                    <!-- 部门ID（必填） -->
                                    <div class="row mb-3">
                                        <label for="id" class="col-sm-2 col-form-label d-flex justify-content-end">部门ID</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" id="id" name="id" required>
                                        </div>
                                    </div>
                                    <!-- 父部门（必填） -->
                                    <div class="row mb-3">
                                        <label for="parentId" class="col-sm-2 col-form-label d-flex justify-content-end">父部门</label>
                                        <div class="col-sm-10">
                                            <select name="parentId" id="parentId" class="form-select" required>
                                                <option value="#" selected>根部门</option>
                                            </select>
                                        </div>
                                    </div>
                                    <!-- 部门名称（必填） -->
                                    <div class="row mb-3">
                                        <label for="name" class="col-sm-2 col-form-label d-flex justify-content-end">部门名称</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" id="name" name="name" required>
                                        </div>
                                    </div>
                                    <!-- 部门类型（必填） -->
                                    <div class="row mb-3">
                                        <label for="type" class="col-sm-2 col-form-label d-flex justify-content-end">部门类型</label>
                                        <div class="col-sm-10">
                                            <select name="type" id="type" class="form-select" required>
                                                <option value="">请选择类型</option>
                                                <option value="总公司">总公司</option>
                                                <option value="分公司">分公司</option>
                                                <option value="业务部门">业务部门</option>
                                                <option value="其它">其它</option>
                                            </select>
                                        </div>
                                    </div>
                                    <!-- 负责人（可选） -->
                                    <div class="row mb-3">
                                        <label for="principal" class="col-sm-2 col-form-label d-flex justify-content-end">负责人</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" id="principal" name="principal">
                                        </div>
                                    </div>
                                    <!-- 联系电话（可选） -->
                                    <div class="row mb-3">
                                        <label for="phone" class="col-sm-2 col-form-label d-flex justify-content-end">联系电话</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" id="phone" name="phone">
                                        </div>
                                    </div>
                                    <!-- 备注（可选） -->
                                    <div class="row mb-3">
                                        <label for="remark" class="col-sm-2 col-form-label d-flex justify-content-end">备注</label>
                                        <div class="col-sm-10">
                                            <textarea class="form-control" id="remark" name="remark" rows="3"></textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </main>
    </div>
</div>

<!-- 引入外部JS -->
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.7/js/bootstrap.bundle.min.js"></script>
<script src="js/utils.js"></script> <!-- 引入通用工具函数 -->
<script src="js/department.js"></script>
</body>
</html>